<template>
  <div class="pageWrapper">
    <common-header />
    <div class="user-info">
      <user-avater :avater="userInfo.userUrl" :userName="userInfo.userName" />
      <div class="content">
        <div class="name-wrap">
          <div class="name">{{ userInfo.userName }}</div>
          <div class="time">{{ userInfo.period }}</div>
        </div>
        <div class="info">考核单位：{{ userInfo.deptNameTree }}</div>
        <div class="info">隶属单位：{{ userInfo.orgName }}</div>
      </div>
    </div>
    <div class="card">
      <div class="title-wrap">
        <div class="title">评定等次</div>
        <div class="link-btn" @click="linkDetail">
          <span>详情</span>
          <img src="@/assets/common/arrow-right-blue.png" />
        </div>
      </div>
      <div class="flex-wrap">
        <div class="label">评定等次</div>
        <div class="status">{{ levelList[userInfo.judgeLevel] }}</div>
      </div>
      <div class="flex-wrap">
        <div class="label">评语</div>
        <div class="comment">{{ userInfo.comment }}</div>
      </div>
    </div>
    <div class="list-card">
      <div class="title-wrap">
        <div class="title">结果异议反馈</div>
        <div class="status during" v-if="result.dissentStatus == 1">处理中</div>
        <div class="status finished" v-else-if="result.dissentStatus == 2">处理完成</div>
        <div class="status unhandled" v-else>未处理</div>
      </div>
      <div>
        <div class="item" v-for="item in result.resultContentVOList" :key="item.id">
          <div class="name-wrap">
            <div class="name">{{ item.userName }}</div>
            <div class="time">{{ item.createTime | timeFormat }}</div>
          </div>
          <div class="content">
            {{ item.resultContent }}
          </div>
        </div>
      </div>
    </div>

    <div class="btn-wrap">
      <div class="add-btn btn-active" @click="linkReply">异议处理</div>
    </div>
    <div class="block"></div>
  </div>
</template>

<script>
import { getObjectionResultList } from "@/api/objectionHandle";
import { getDictionaryByType } from "@/api/common";
import { formatTime } from "@/utils";
export default {
  data() {
    return {
      form: {
        appraisalId: 0,
        dissentType: 1 //考核类型（1：平时考核 2：年度考核）,
        // userType: 2 //用户类型（1：提交异议申请人 2：处理异议人）
      },
      userInfo: {},
      result: {},
      levelList: {}
    };
  },
  filters: {
    timeFormat(time) {
      return formatTime(new Date(time), "yyyy年MM月dd日 HH:mm:ss");
    }
  },
  created() {
    this.userInfo = JSON.parse(sessionStorage.getItem("objectUser"));
    this.form.appraisalId = this.$route.query.id;
    this.form.dissentType = this.$route.query.is_year == "1" ? 2 : 1;
    this.initData();
    this.getLevel();
  },
  methods: {
    getLevel() {
      let type = this.$route.query.is_year == "1" ? "yearAssess" : "quarterAssess";
      this.levelList = {};
      getDictionaryByType(type).then(res => {
        res.data.forEach(ele => {
          this.$set(this.levelList, ele.dictValue, ele.dictLabel);
        });
      });
    },
    initData() {
      getObjectionResultList(this.form).then(res => {
        this.result = res.data;
      });
    },
    linkReply() {
      this.$router.push({
        path: "/objectionHandle/reply",
        query: {
          id: this.result.id,
          is_year: this.$route.query.is_year
        }
      });
    },
    linkDetail() {
      this.$router.push({
        path: "/appraisalProcess/detail",
        query: {
          type: 2,
          status: 1,
          id: this.$route.query.id,
          is_year: this.$route.query.is_year,
          from: "objection"
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
.user-info {
  display: flex;
  background: #fff;
  margin: 20px 16px 12px;
  border-radius: 8px;
  padding: 16px;

  .user {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    margin-right: 12px;
    background: #2492ff;
    color: #fff;
    text-align: center;
    line-height: 40px;
    font-size: 14px;
  }

  .content {
    flex: 1;
    line-height: 17px;
    color: #a3a7ad;

    .name-wrap {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 12px;

      .name {
        font-size: 16px;
        line-height: 22px;
        color: #333;
      }

      .time {
        color: #606266;
      }
    }

    .info {
      margin-top: 6px;
    }
  }
}

.card {
  background: #fff;
  margin: 12px 16px;
  border-radius: 8px;
  padding: 16px;

  .title-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .link-btn {
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #b3b3b3;
      white-space: nowrap;

      img {
        height: 12px;
        margin-left: 8px;
      }
    }
  }

  .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #000;
    font-size: 16px;
    line-height: 22px;

    span {
      margin-left: 12px;
      color: #f60e36;
      font-size: 12px;
    }
  }

  .label {
    color: #808080;
    margin-right: 12px;
  }

  .status {
    color: #f60e36;
  }
}

.flex-wrap {
  display: flex;
  align-items: flex-start;
  margin-top: 12px;
  line-height: 20px;
  font-size: 14px;
}

.list-card {
  margin: 12px 16px 30px;
  background: #fff;
  border-radius: 8px;
  padding: 16px;

  .title-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .title {
      font-size: 16px;
      color: #000;
    }

    .status {
      line-height: 26px;
      border-radius: 4px;
      font-size: 12px;
      padding: 0 10px;
    }

    .during {
      color: #ffa700;
      background: rgba(255, 167, 0, 0.1);
    }

    .finished {
      color: #1b68eb;
      background: rgba(27, 104, 235, 0.1);
    }

    .unhandled {
      color: #808080;
      background: rgba(128, 128, 128, 0.1);
    }
  }

  .item {
    border-bottom: 1px solid #ebebeb;
    padding-bottom: 12px;

    &:last-child {
      border: none;
      padding-bottom: 0;
    }
  }

  .name-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 20px;

    .name {
      color: #4d4d4d;
    }

    .time {
      color: #b3b3b3;
    }
  }

  .content {
    font-size: 14px;
    line-height: 22px;
    color: #808080;
  }
}

.btn-wrap {
  position: fixed;
  width: 100%;
  bottom: 0;
  left: 0;
}

.add-btn {
  text-align: center;
  margin: 0 16px 24px;
  color: #fff;
  line-height: 52px;
  background: #2492ff;
  border-radius: 12px;
  font-size: 14px;
}

.block {
  height: 76px;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}
</style>
